package com.psbc.online_xdclass.utils;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class BaseCache {
    private Cache<String,Object> tenMinuteCache = CacheBuilder.newBuilder()
            .initialCapacity(10)//缓存初始容量
            .maximumSize(100)//最大容量
            .expireAfterWrite(600, TimeUnit.SECONDS)//过期时间
            .concurrencyLevel(5)//并行数量
            .recordStats()//记录缓存命中率
            .build();
    private Cache<String,Object> oneHourCache = CacheBuilder.newBuilder()
            .initialCapacity(30)//缓存初始容量
            .maximumSize(100)//最大容量
            .expireAfterWrite(3600, TimeUnit.SECONDS)//过期时间
            .concurrencyLevel(5)//并行数量
            .recordStats()//记录缓存命中率
            .build();

    public Cache<String, Object> getOneHourCache() {
        return oneHourCache;
    }

    public void setOneHourCache(Cache<String, Object> oneHourCache) {
        this.oneHourCache = oneHourCache;
    }

    public Cache<String, Object> getTenMinuteCache() {
        return tenMinuteCache;
    }

    public void setTenMinuteCache(Cache<String, Object> tenMinuteCache) {
        this.tenMinuteCache = tenMinuteCache;
    }
}
